package com.example.demo.quartz.job;

import com.example.demo.entity.dataSource1.MemberEntity;
import com.example.demo.service.dataSource1.impl.MemberService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;


/**
 * Created by Wen Gao on 2018/7/12.
 */
@Component
@EnableScheduling
//@DisallowConcurrentExecution // 开启该注解则不允许并发
public class QuartzJobPushMember implements IQuartzJob {

    Logger logger = LogManager.getLogger(this.getClass());

    long memberUid = 999999999;// 默认设置为999999999

    String jobId = "1";
    String jobName = this.getClass().getSimpleName();
    String jobGroup = "group1";
    String jobCron = "0/20 * * * * ?";

    @Autowired
    private MemberService memberService;

    public QuartzJobPushMember() {
    }

    public QuartzJobPushMember(String jobId, String jobName, String jobGroup) {
        this.setJobId(jobId);
        this.setJobName(jobName);
        this.setJobGroup(jobGroup);
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public void setJobGroup(String jobGroup) {
        this.jobGroup = jobGroup;
    }

    public void setJobCron(String jobCron) {
        this.jobCron = jobCron;
    }

    @Override
    public String getJobId() {
        return "1";
    }

    @Override
    public String getJobName() {
        return this.getClass().getSimpleName();
    }

    @Override
    public String getJobCron() {
        return "0/20 * * * * ?";// 20秒一次
    }

    @Override
    public String getJobGroup() {
        return "group1";
    }


    @Override
    public void execute() {
        MemberEntity memberEntity = memberService.getMemberByMemberUid(memberUid);
        logger.info(memberEntity.toJson());
        try {
            logger.info("QuartzJobPushMember推送member任务 start");
            Thread.sleep(3000);
            logger.info("QuartzJobPushMember推送member任务 end");
        } catch (InterruptedException e) {
            e.printStackTrace();
            logger.error(e);
        }
    }


}
